package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.CaseComplaintReason;
import com.ktgj.customer.service.ICaseComplaintReasonService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 投诉工单_投诉原因Controller
 * 
 * @author ruoyi
 * @date 2022-05-27
 */
@RestController
@RequestMapping("/reason")
public class CaseComplaintReasonController extends BaseController
{
    @Autowired
    private ICaseComplaintReasonService caseComplaintReasonService;

    /**
     * 查询投诉工单_投诉原因列表
     */
    @PreAuthorize(hasPermi = "system:reason:list")
    @GetMapping("/list")
    public TableDataInfo list(CaseComplaintReason caseComplaintReason)
    {
        startPage();
        List<CaseComplaintReason> list = caseComplaintReasonService.selectCaseComplaintReasonList(caseComplaintReason);
        return getDataTable(list);
    }

    /**
     * 导出投诉工单_投诉原因列表
     */
    @PreAuthorize(hasPermi = "system:reason:export")
    @Log(title = "投诉工单_投诉原因", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseComplaintReason caseComplaintReason) throws IOException
    {
        List<CaseComplaintReason> list = caseComplaintReasonService.selectCaseComplaintReasonList(caseComplaintReason);
        ExcelUtil<CaseComplaintReason> util = new ExcelUtil<CaseComplaintReason>(CaseComplaintReason.class);
        util.exportExcel(response, list, "投诉工单_投诉原因数据");
    }

    /**
     * 获取投诉工单_投诉原因详细信息
     */
    @PreAuthorize(hasPermi = "system:reason:query")
    @GetMapping(value = "/{complaintReasonId}")
    public AjaxResult getInfo(@PathVariable("complaintReasonId") Long complaintReasonId)
    {
        return AjaxResult.success(caseComplaintReasonService.selectCaseComplaintReasonById(complaintReasonId));
    }

    /**
     * 新增投诉工单_投诉原因
     */
    @PreAuthorize(hasPermi = "system:reason:add")
    @Log(title = "投诉工单_投诉原因", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseComplaintReason caseComplaintReason)
    {
        return toAjax(caseComplaintReasonService.insertCaseComplaintReason(caseComplaintReason));
    }

    /**
     * 修改投诉工单_投诉原因
     */
    @PreAuthorize(hasPermi = "system:reason:edit")
    @Log(title = "投诉工单_投诉原因", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaseComplaintReason caseComplaintReason)
    {
        return toAjax(caseComplaintReasonService.updateCaseComplaintReason(caseComplaintReason));
    }

    /**
     * 删除投诉工单_投诉原因
     */
    @PreAuthorize(hasPermi = "system:reason:remove")
    @Log(title = "投诉工单_投诉原因", businessType = BusinessType.DELETE)
	@DeleteMapping("/{complaintReasonIds}")
    public AjaxResult remove(@PathVariable Long[] complaintReasonIds)
    {
        return toAjax(caseComplaintReasonService.deleteCaseComplaintReasonByIds(complaintReasonIds));
    }

    /**
     *查询投诉工单_投诉原因列表
     * @return投诉工单_投诉原因集合
     */
    @PostMapping("/selectReasonList")
    public AjaxResult selectReasonList(){
        List<CaseComplaintReason> list=caseComplaintReasonService.selectReasonList();
        if(list.size()>0){
            return  AjaxResult.success(list);
        }else {
            return  AjaxResult.success("没有相关数据");
        }
    }
}
